import { DefaultHeaders, HuobiUrlPrex } from "./Config";
import HttpManager from "./HttpManager";
import Helper from "./util/Helper";
import JSONbig = require('json-bigint');

async function getDemo() {
    const get_context_path = "/v1/account/accounts";
    let getPath = Helper.preGet(get_context_path)
    let result = await HttpManager.Ins.get(getPath, {
        timeout: 5000,
        headers: DefaultHeaders
    })
    let getResult: {
        status: string,
        data: { id: number, type: string, subtype: string, state: string }[]
    } = JSON.parse(result)
    console.log(getResult.data);
    let spotAccount = getResult.data.find((item) => {
        return item.type == 'spot'
    })
    postDemo(spotAccount.id);
}

async function postDemo(id: number) {
    const post_context_path = "/v1/order/orders/place";
    const post_body = {
        "account-id": `${id}`,
        "amount": "10",
        "source": "spot-api",
        "symbol": "trxusdt",
        "type": "buy-market",
        "client-order-id": "a0001"
    }
    let postInfo = Helper.prePost(post_context_path, post_body)
    let post_result = await HttpManager.Ins.post(postInfo.post_url, postInfo.body, {
        timeout: 5000,
        headers: DefaultHeaders
    })
    let postResult = JSONbig.parse(post_result)
    console.log(postResult);
}
getDemo();
